import os

basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
    SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DEFAULT_DATABASE_URI')

    SQLALCHEMY_MYSQL_ONLINE_DATABASE_URI = 'mysql+pymysql://root:Luck158,@localhost:93306/ironman_prod'
    SQLALCHEMY_CG_URI = 'mysql+pymysql://root:BICI123456@192.168.40.214:3306/cg'
    SQLALCHEMY_DATABASE_URI = SQLALCHEMY_MYSQL_ONLINE_DATABASE_URI
    SQLALCHEMY_BINDS = {
        'serve_engine': SQLALCHEMY_MYSQL_ONLINE_DATABASE_URI,
        'cg': SQLALCHEMY_CG_URI
    }

    MYSQL_HOST = "192.168.40.214"
    MYSQL_PORT = 3306
    MYSQL_USER = "root"
    MYSQL_PASSWORD = "BICI123456"
    MYSQL_DATABASE = "cg"

    IRONMAN_MYSQL_HOST = "192.168.40.214"
    IRONMAN_MYSQL_PORT = 13306
    IRONMAN_MYSQL_USER = "root"
    IRONMAN_MYSQL_PASSWORD = "Cisco#123"
    IRONMAN_MYSQL_DATABASE = "ironman_prod"

    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 超过连接池大小外最多创建的连接
    SQLALCHEMY_MAX_OVERFLOW = 0
    # 连接池大小
    SQLALCHEMY_POOL_SIZE = 5
    # 池中没有线程最多等待的时间，否则报错
    SQLALCHEMY_POOL_TIMEOUT = 30
    # 多久之后对线程池中的线程进行一次连接的回收（重置）
    SQLALCHEMY_POOL_RECYCLE = 3600
    JSON_AS_ASCII = False
    # 以前不能设置 POOL_CLASS, 默认QueuePool 有了update https://github.com/pallets/flask-sqlalchemy/pull/684

    # 从数据库按需提取历史数据，载入内存

    # 是否启动历史数据分析
    GAOLU_PARAM_DIST_ENABLE = True
    GAOLU_PARAM_QUAN_ENABLE = True
    HANFAN_PARAM_DIST_ENABLE = True
    HANFAN_PARAM_QUAN_ENABLE = True

    # 是否持久化历史分析结果到文件
    PERSIST_CONTAINER_ENABLE = True
    # 是否从持久化文件入读
    CONTAINER_IS_LOADED = True
    GAOLU_PARAM_HISTORY_BINS = 20
    HANFAN_PARAM_HISTORY_BINS = 24

    # TODO 用户可以为历史分布表自行选择时间段，为了提高效率，以后提供做好的分布表，可以直接load, 不用计算
    GAOLU_PARAM_HISTORY_START = "2018-10-01 00:00:00"
    GAOLU_PARAM_HISTORY_END = "2018-12-31 00:00:00"

    HANFAN_PARAM_HISTORY_START = "2020-01-01 00:00:00"
    HANFAN_PARAM_HISTORY_END = "2021-12-31 00:00:00"

    # core params for coreData controller
    CORE_PARAMS = [
        "CG_LT_GL_GL04_TQXZS",
        "CG_LT_GL_GL04_ZXQL",
        "CG_LT_GL_GL04_LFLL",
        "CG_LT_GL_GL04_FYLL",
        "CG_LT_GL_GL04_FCokeRate",
        "CG_LT_GL_GL04_FCoalRate",
        "CG_LT_GL_GL04_RFWD",
        "CG_LT_GL_GL04_SBYCZB",
        "CG_LT_GL_GL04_XBYCZB",
        "DateTime"
    ]

    # main params for mainData controller
    MAIN_PARAMS = [
        "CG_SJ_SJJ_SJ02_HHLSF",  # 混合料水分
        "CG_SJ_SJJ_SJ02_HHLDLZ",  # 混合料斗料重
        "CG_SJ_SJJ_SJ02_SJJXS",  # 烧结机机速
        "CG_SJ_SJJ_SJ02_YGJXS",  # 圆辊速度
        "CG_SJ_SJJ_SJ02_JGJXS",  # 九辊速度
        "CG_SJ_SJJ_SJ02_DHWD",  # 点火温度
        "CG_SJ_SJJ_SJ02_YDWDB",  # 烟道温度北
        "CG_SJ_SJJ_SJ02_YDWDN",  # 烟道温度南
        "CG_SJ_SJJ_SJ02_SJDYDFY01",  # 南烟道负压
        "CG_SJ_SJJ_SJ02_SJDYDFY02",  # 北烟道负压
        "DateTime"
    ]

    # core params for coreData controller
    HANFAN_CORE_PARAMS = [
        "CG_LT_GL_GL04_TQXZS",
        "CG_LT_GL_GL04_FYLL",
        "CG_LT_GL_GL04_ZXQL",
        "CG_LT_GL_GL04_RFWD",
        "CG_LT_GL_GL04_LFLL",
        "CG_LT_GL_GL04_FCokeRate",
        "CG_LT_GL_GL04_FCoalRate",
        "CG_LT_GL_GL04_XBYCZB",
        "CG_LT_GL_GL04_SBYCZB",
        "DateTime"
    ]

    # 定义，自动清除的数据记录
    GAOLU_CLEAN_START = '2018-12-31 23:59:59'
    GAOLU_CLEAN_END = '2028-12-31 23:59:59'

    KAFKA_SERVERS = ['192.168.40.214:9092', '192.168.40.214:9093', '192.168.40.214:9094']

    #########################
    #  redis
    #########################
    REDIS_HOST = 'ironman-redis-container'
    REDIS_PORT = 6379
    REDIS_DBID = 1
    REDIS_PASSWORD = 'ironBackRedis123'
